#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main() {
    srand(time(0));
    char retry;

    do {
        // 添加难度级别选择
        int level;
        printf("选择难度(1-简单[1-50], 2-中等[1-100], 3-困难[1-200]): ");
        scanf("%d", &level);

        // 根据难度生成随机数
        int target;
        switch(level) {
            case 1: target = rand() % 50 + 1; break;
            case 2: target = rand() % 100 + 1; break;
            case 3: target = rand() % 200 + 1; break;
            default: target = rand() % 100 + 1;
        }

        int guess, attempts = 0;

        printf("猜一个1-%d的整数：", level == 1 ? 50 : (level == 3 ? 200 : 100));
        while (1) {
            scanf("%d", &guess);
            attempts++;
            if (guess < target) {
                printf("小了！再试一次：");
            } else if (guess > target) {
                printf("大了！再试一次：");
            } else {
                printf("恭喜！用了%d次猜中\n", attempts);
                break;
            }
        }

        // **添加重试询问**
        printf("再玩一次？(y/n): ");
        scanf(" %c", &retry);  // %c前加空格，吸收输入缓冲区的换行符
    } while (retry == 'y' || retry == 'Y');

    return 0;
}

